// pages/user/shoppingCart/coloruiShoppingCart.js
const app = getApp();
const http = require('../../../utils/http.js')
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },
  options: {
    addGlobalClass: true,
  },
  lifetimes: {
    attached: function() {
      this.setData({
        customer: app.globalData.customer
      })
      this.interfaceCall();
    }
  },
  pageLifetimes: {
    show: function() {
      // 页面被展示
      this.interfaceCall();
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    cartList:null,
    x: 0,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //删除收藏商品
    handleDeleteProduct:function(e){
      var cartList=this.data.cartList
      cartList.splice(e.currentTarget.dataset.productindex,1)
      this.setData({
        cartList:cartList,
        x: 0
      })
      wx.setStorageSync('cart',cartList)
      wx.showToast({
        title:'已删除本条收藏',
        icon:'none'
      })
    },
    //去支付
    zfBtn:function(e){
      wx.navigateTo({
        url: '/pages/home/couponDetail/index?stockId=' + e.currentTarget.dataset.stockid
      });
    },
    //去挑选
    qtxBtn:function(){
      wx.reLaunch({
        url: '/pages/index/index'
      })
    },
    interfaceCall:function(){
      if(wx.getStorageSync('cart').length){
        this.setData({
          cartList:wx.getStorageSync('cart')
        })
      }
      // http.get('/api/index/selectActivity', {type: 5}).then(res => {
      //   if (res.code == 200) {
      //       this.setData({
      //           czmsItem: res.result
      //       })
      //   }
      // })
    },
  }
})
